/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package turtle.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectContainmentEList;
import org.eclipse.emf.ecore.util.InternalEList;

import turtle.Action;
import turtle.Choregraphy;
import turtle.Color;
import turtle.Farm;
import turtle.Stage;
import turtle.TurtlePackage;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Stage</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link turtle.impl.StageImpl#getLength <em>Length</em>}</li>
 *   <li>{@link turtle.impl.StageImpl#getHeight <em>Height</em>}</li>
 *   <li>{@link turtle.impl.StageImpl#getChrs <em>Chrs</em>}</li>
 *   <li>{@link turtle.impl.StageImpl#getColor <em>Color</em>}</li>
 *   <li>{@link turtle.impl.StageImpl#getFarms <em>Farms</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class StageImpl extends EObjectImpl implements Stage {
	/**
	 * The default value of the '{@link #getLength() <em>Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLength()
	 * @generated
	 * @ordered
	 */
	protected static final int LENGTH_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getLength() <em>Length</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getLength()
	 * @generated
	 * @ordered
	 */
	protected int length = LENGTH_EDEFAULT;

	/**
	 * The default value of the '{@link #getHeight() <em>Height</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getHeight()
	 * @generated
	 * @ordered
	 */
	protected static final int HEIGHT_EDEFAULT = 0;

	/**
	 * The cached value of the '{@link #getHeight() <em>Height</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getHeight()
	 * @generated
	 * @ordered
	 */
	protected int height = HEIGHT_EDEFAULT;

	/**
	 * The cached value of the '{@link #getChrs() <em>Chrs</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getChrs()
	 * @generated
	 * @ordered
	 */
	protected EList<Choregraphy> chrs;

	/**
	 * The cached value of the '{@link #getColor() <em>Color</em>}' containment reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getColor()
	 * @generated
	 * @ordered
	 */
	protected Color color;

	/**
	 * The cached value of the '{@link #getFarms() <em>Farms</em>}' containment reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getFarms()
	 * @generated
	 * @ordered
	 */
	protected EList<Farm> farms;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected StageImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return TurtlePackage.Literals.STAGE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getLength() {
		return length;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setLength(int newLength) {
		int oldLength = length;
		length = newLength;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TurtlePackage.STAGE__LENGTH, oldLength, length));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public int getHeight() {
		return height;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setHeight(int newHeight) {
		int oldHeight = height;
		height = newHeight;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TurtlePackage.STAGE__HEIGHT, oldHeight, height));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Choregraphy> getChrs() {
		if (chrs == null) {
			chrs = new EObjectContainmentEList<Choregraphy>(Choregraphy.class, this, TurtlePackage.STAGE__CHRS);
		}
		return chrs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public Color getColor() {
		return color;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public NotificationChain basicSetColor(Color newColor, NotificationChain msgs) {
		Color oldColor = color;
		color = newColor;
		if (eNotificationRequired()) {
			ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, TurtlePackage.STAGE__COLOR, oldColor, newColor);
			if (msgs == null) msgs = notification; else msgs.add(notification);
		}
		return msgs;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setColor(Color newColor) {
		if (newColor != color) {
			NotificationChain msgs = null;
			if (color != null)
				msgs = ((InternalEObject)color).eInverseRemove(this, EOPPOSITE_FEATURE_BASE - TurtlePackage.STAGE__COLOR, null, msgs);
			if (newColor != null)
				msgs = ((InternalEObject)newColor).eInverseAdd(this, EOPPOSITE_FEATURE_BASE - TurtlePackage.STAGE__COLOR, null, msgs);
			msgs = basicSetColor(newColor, msgs);
			if (msgs != null) msgs.dispatch();
		}
		else if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, TurtlePackage.STAGE__COLOR, newColor, newColor));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<Farm> getFarms() {
		if (farms == null) {
			farms = new EObjectContainmentEList<Farm>(Farm.class, this, TurtlePackage.STAGE__FARMS);
		}
		return farms;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void display() {
		// TODO: implement this method
		// Ensure that you remove @generated or mark it @generated NOT
		
		
		EList<Choregraphy> chore= getChrs();
		
		for(Choregraphy c: chore){
			EList<Action> actions=  c.getActions();
			
			for(Action a: actions)
				System.out.println(a.toString());
			
			System.out.println("Fin .");
		}
		
	}


	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
		switch (featureID) {
			case TurtlePackage.STAGE__CHRS:
				return ((InternalEList<?>)getChrs()).basicRemove(otherEnd, msgs);
			case TurtlePackage.STAGE__COLOR:
				return basicSetColor(null, msgs);
			case TurtlePackage.STAGE__FARMS:
				return ((InternalEList<?>)getFarms()).basicRemove(otherEnd, msgs);
		}
		return super.eInverseRemove(otherEnd, featureID, msgs);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case TurtlePackage.STAGE__LENGTH:
				return getLength();
			case TurtlePackage.STAGE__HEIGHT:
				return getHeight();
			case TurtlePackage.STAGE__CHRS:
				return getChrs();
			case TurtlePackage.STAGE__COLOR:
				return getColor();
			case TurtlePackage.STAGE__FARMS:
				return getFarms();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case TurtlePackage.STAGE__LENGTH:
				setLength((Integer)newValue);
				return;
			case TurtlePackage.STAGE__HEIGHT:
				setHeight((Integer)newValue);
				return;
			case TurtlePackage.STAGE__CHRS:
				getChrs().clear();
				getChrs().addAll((Collection<? extends Choregraphy>)newValue);
				return;
			case TurtlePackage.STAGE__COLOR:
				setColor((Color)newValue);
				return;
			case TurtlePackage.STAGE__FARMS:
				getFarms().clear();
				getFarms().addAll((Collection<? extends Farm>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case TurtlePackage.STAGE__LENGTH:
				setLength(LENGTH_EDEFAULT);
				return;
			case TurtlePackage.STAGE__HEIGHT:
				setHeight(HEIGHT_EDEFAULT);
				return;
			case TurtlePackage.STAGE__CHRS:
				getChrs().clear();
				return;
			case TurtlePackage.STAGE__COLOR:
				setColor((Color)null);
				return;
			case TurtlePackage.STAGE__FARMS:
				getFarms().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case TurtlePackage.STAGE__LENGTH:
				return length != LENGTH_EDEFAULT;
			case TurtlePackage.STAGE__HEIGHT:
				return height != HEIGHT_EDEFAULT;
			case TurtlePackage.STAGE__CHRS:
				return chrs != null && !chrs.isEmpty();
			case TurtlePackage.STAGE__COLOR:
				return color != null;
			case TurtlePackage.STAGE__FARMS:
				return farms != null && !farms.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (length: ");
		result.append(length);
		result.append(", height: ");
		result.append(height);
		result.append(')');
		return result.toString();
	}

} //StageImpl
